<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>LagouPhone秒杀</title>
    <script type="text/javascript" src="https://www.lgstatic.com/lg-www-fed/pkg/vendor_e97ade5.js"></script>
</head>
<body>
<table>
    <tr>
        <td>拉勾发iphone12了，限量100台</td>
    </tr>
    <tr>
        <td id="current_stock" th:text="'还剩'+${currentStock}+'台'">还剩100台</td>
    </tr>
    <tr>
        <td><input type="button" name="startSecKill" value="开始秒杀" id="toSecKill" /></td>
    </tr>
</table>
<script>
    $('#toSecKill').click(function () {
        $.ajax({
            url:'http://localhost:8080/seckill/create_order',
            type:'get',
            data:{'userId':151536466},
            success: function (data) {
                console.log(data);
                alert(data.msg);
                if(data.code == 0){
                    window.location.href = "/seckill/awaitPay?orderId="+data.orderId;
                }
            }
        });
    });
    var getStock = function () {
        $.ajax({
            url:'http://localhost:8080/seckill/getStock',
            type:'get',
            data:{},
            success: function (rs) {
                console.log(rs);
                $('#current_stock').html('还剩'+rs.data+'台');
                setTimeout("getStock();",500);
            }
        });
    };
    getStock();
</script>
</body>
</html>
